package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.entity.Bed;
import com.neuedu.mapper.BedMapper;
import com.neuedu.service.BedService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

/**
 * <p>
 * 床位表 服务实现类
 * </p>
 *
 * @author wangyu
 * @since 2025-10-15
 */
@Service
public class BedServiceImpl extends ServiceImpl<BedMapper, Bed> implements BedService {

    @Override
    public IPage<Bed> list(Integer pageNo, Integer pageSize, String bedNo) {
        QueryWrapper<Bed> wrapper = new QueryWrapper<>();
        if (StringUtils.isNoneBlank(bedNo)) {
            wrapper.like("bed_no", bedNo);
        }
        wrapper.orderByDesc("id");
        return this.page(new Page<>(pageNo, pageSize), wrapper);
    }

    @Override
    public boolean updateStatus(Integer id, Integer status) {
        Bed bed = new Bed();
        bed.setId(id);
        bed.setBedStatus(status);
        return this.updateById(bed);
    }
}
